home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / infoserv / gopher / Unix / GopherTools / xferstats.gopher.Z / xferstats.gopher
Encoding:
Text File  |  1994-08-10  |  10.5 KB  |  362 lines

  1. Xref: feenix.metronet.com comp.infosystems.gopher:4460
  2. Newsgroups: comp.infosystems.gopher
  3. Path: feenix.metronet.com!news.utdallas.edu!tamsun.tamu.edu!cs.utexas.edu!uwm.edu!cs.uwp.edu!datta
  4. From: datta@cs.uwp.edu (David Datta)
  5. Subject: new Log stats program 
  6. Message-ID: <1993Aug14.064250.9293@cs.uwp.edu>
  7. Organization: University of Wisconsin - Parkside
  8. X-Newsreader: TIN [version 1.2 PL1]
  9. Date: Sat, 14 Aug 1993 06:42:50 GMT
  10. Lines: 350
  11.  
  12. I have just finished modifying the xferstats program that analyzes data
  13. from wuarchive's ftpd program to also handle Gopher logfiles.
  14.  
  15. It only does stats on Gopher file transfers (it doesn't do stats on
  16. directory requests.) It turns out, the music archives gets about 18,000
  17. files sent out a day.
  18.  
  19. This xferstats is quite different from the one that is distributed, 
  20. I take the blame for all bugs and I appreciate comments.
  21.  
  22. Edit the defaults at the top for your sites....
  23.  
  24. (Don't forget to clip the signature from the end...)
  25.  
  26. ----CUT HERE -----------------------------------------------------------------
  27. #! /usr/local/bin/perl
  28. # ---------------------------------------------------------------------------
  29. #
  30. # USAGE: xferstats <options>
  31. #
  32. # OPTIONS:
  33. #       -f <filename>   Use <filename> for the log file
  34. #       -r              include real users 
  35. #       -a              include anonymous users 
  36. #       -h        include report on hourly traffic
  37. #       -d        include report on domain traffic
  38. #       -t        report on total traffic by section
  39. #       -D <domain>     report only on traffic from <domain>
  40. #       -l <depth>      Depth of path detail for sections
  41. #       -s <section>    Section to report on, For example: -s /pub will report
  42. #                only on paths under /pub
  43. #       -g              Process a Gopher file, not an FTP file
  44. #
  45. # ---------------------------------------------------------------------------
  46.  
  47. # edit the next two lines to customize for your domain.
  48. # This will allow your domain to be seperated in the domain listing.
  49.  
  50. $mydom1 = "uwp";
  51. $mydom2 = "edu";
  52.  
  53. # edit the next line to customize for your default log file
  54. $usage_file = "/usr/adm/xferlog";
  55. $gopherlog = "/usr/adm/gopherlog";
  56.  
  57. # Edit the following lines for default report settings.
  58. # Entries defined here will be over-ridden by the command line.
  59.  
  60. $opt_h = 1; 
  61. $opt_d = 0;
  62. $opt_t = 1;
  63. $opt_l = 3;
  64.  
  65. require 'getopts.pl';
  66. &Getopts('f:rahdD:l:s:g');
  67.  
  68. if ($opt_r) { $real = 1;}
  69. if ($opt_a) { $anon = 1;}
  70. if ($real == 0 && $anon == 0) { $anon = 1; }
  71. if ($opt_g) {$usage_file = $gopherlog;}
  72. if ($opt_f) {$usage_file = $opt_f;}
  73.  
  74. open (LOG,$usage_file) || die "Error opening usage log file: $usage_file\n";
  75.  
  76. if ($opt_g) {print "This report is for GOPHER transfers.\n";}
  77. else {print "This report is for FTP transfers.\n";}
  78.  
  79. if ($opt_D) {print "Transfer Totals include the '$opt_D' domain only.\n";
  80.          print "All other domains are filtered out for this report.\n\n";}
  81.  
  82. if ($opt_s) {print "Transfer Totals include the '$opt_s' section only.\n";
  83.          print "All other sections are filtered out for this report.\n\n";}
  84.  
  85. line: while (<LOG>) {
  86.  
  87.    @line = split;
  88.    if (!$opt_g) {
  89.     next if ($#line != 16);
  90.     next if (!$anon && $line[12] eq "a");
  91.     next if (!$real && $line[12] eq "r");
  92.     }
  93.  
  94.    $daytime = substr($_, 0, 10) . substr($_, 19, 5);
  95.    $time = substr($_,11,2); 
  96.  
  97.    if ($opt_g) {
  98.     if ( $line[9] eq "range") {
  99.         $fsize=$line[12]-$line[10];
  100.         $fname=$line[15];
  101.     } else {
  102.         {next if ( $line[9] ne "file");}
  103.         $fname=$line[10];
  104.            $fsize = (-s "/usr/ftp/".$line[10]);
  105.     }}
  106.    else {
  107.     $fname=$line[8];
  108.     $fsize = $line[7];
  109.         if ($fname eq "\.") { $fname = "/unreadable/filename";}
  110.    }
  111.  
  112.    next if (substr($fname,0,length("$opt_s")) ne "$opt_s");
  113.    $fname = substr($fname,length("$opt_s"));
  114.    @path = split(/\//, $fname);
  115.  
  116. # Things in the top-level directory are assumed to be informational files
  117.  
  118.    if ($#path == 1)
  119.       { $pathkey = "Index/Informational Files"; }
  120.       else {
  121.     $pathkey = "";
  122.     for ($i=1; $i <= $#path-1 && $i <= $opt_l;$i++) {
  123.         $pathkey = $pathkey . "/" . $path[$i];
  124.         }
  125.     }
  126.  
  127.    if ($opt_g)
  128.     {$afield=$line[7];}
  129.    else
  130.     {$afield=$line[6];}
  131.  
  132.    $afield =~ tr/A-Z/a-z/;
  133.  
  134.    @address = split(/\./, $afield);
  135.  
  136.    $domain = $address[$#address];
  137.    if ($domain eq "$mydom2" && $address[$#address-1] eq "$mydom1")
  138.       { $domain = $mydom1 . "." . $mydom2; }
  139.    if ( int($address[0]) > 0 || $#address < 2 )
  140.       { $domain = "unresolved"; }
  141.  
  142.    $count = 1;
  143.    if ($opt_D)
  144.      {if (substr($domain,0,length("$opt_D")) eq "$opt_D" ) { $count = 1;} else
  145.      {$count = 0;}
  146.      }
  147.  
  148.  
  149.    if ($count) {
  150.  
  151.  
  152.    $xferfiles++;                                # total files sent
  153.    $xfertfiles++;                               # total files sent
  154.    $xferfiles{$daytime}++;                      # files per day
  155.    $groupfiles{$pathkey}++;                     # per-group accesses
  156.    $domainfiles{$domain}++;
  157.  
  158.    $xfersecs{$daytime}    += $line[5];          # xmit seconds per day
  159.    $domainsecs{$domain}   += $line[5];        # xmit seconds for domain
  160.    $xferbytes{$daytime}   += $fsize;        # bytes per day
  161.    $domainbytes{$domain}  += $line[7];        # xmit bytes to domain
  162.    $xferbytes             += $fsize;        # total bytes sent     
  163.    $groupbytes{$pathkey}  += $fsize;        # per-group bytes sent
  164.  
  165.    $xfertfiles{$time}++;                        # files per hour
  166.    $xfertsecs{$time}      += $line[5];          # xmit seconds per hour
  167.    $xfertbytes{$time}     += $fsize;        # bytes per hour
  168.    $xfertbytes            += $fsize;        # total bytes sent
  169.    }
  170. }
  171. close LOG;
  172.  
  173. @syslist = keys(systemfiles);
  174. @dates = sort datecompare keys(xferbytes);
  175.  
  176. if ($xferfiles == 0) {die "There was no data to process.\n";}
  177.  
  178.  
  179. print "TOTALS FOR SUMMARY PERIOD ", $dates[0], " TO ", $dates[$#dates], "\n\n";
  180. printf ("Files Transmitted During Summary Period  %12.0f\n", $xferfiles);
  181. printf ("Bytes Transmitted During Summary Period  %12.0f\n", $xferbytes); 
  182. printf ("Systems Using Archives                   %12.0f\n\n", $#syslist+1);
  183.  
  184. printf ("Average Files Transmitted Daily          %12.0f\n",
  185.    $xferfiles / ($#dates + 1));
  186. printf ("Average Bytes Transmitted Daily          %12.0f\n",
  187.    $xferbytes / ($#dates + 1));
  188.  
  189. format top1 =
  190.  
  191. Daily Transmission Statistics
  192.  
  193.                  Number Of    Number of    Average    Percent Of  Percent Of
  194.      Date        Files Sent  Bytes  Sent  Xmit  Rate  Files Sent  Bytes Sent
  195. ---------------  ----------  -----------  ----------  ----------  ----------
  196. .
  197.  
  198. format line1 =
  199. @<<<<<<<<<<<<<<  @>>>>>>>>>  @>>>>>>>>>>  @>>>>>>>>>  @>>>>>>>    @>>>>>>>  
  200. $date,           $nfiles,    $nbytes,     $avgrate,   $pctfiles,  $pctbytes
  201. .
  202.  
  203. $^ = top1;
  204. $~ = line1;
  205.  
  206. foreach $date ( sort datecompare keys(xferbytes) ) {
  207.  
  208.    $nfiles   = $xferfiles{$date};
  209.    $nbytes   = $xferbytes{$date};
  210.    $avgrate  = sprintf("%5.1f KB/s", $xferbytes{$date}/$xfersecs{$date}/1000);
  211.    $pctfiles = sprintf("%8.2f", 100*$xferfiles{$date} / $xferfiles);
  212.    $pctbytes = sprintf("%8.2f", 100*$xferbytes{$date} / $xferbytes);
  213.    write;
  214. }
  215.  
  216. if ($opt_t) {
  217. format top2 =
  218.  
  219. Total Transfers from each Archive Section (By bytes)
  220.  
  221.                                                  ---- Percent  Of ----
  222.      Archive Section      Files Sent Bytes Sent  Files Sent Bytes Sent
  223. ------------------------- ---------- ----------- ---------- ----------
  224. .
  225.  
  226. format line2 =
  227. @<<<<<<<<<<<<<<<<<<<<<<<< @>>>>>>>>> @>>>>>>>>>> @>>>>>>>   @>>>>>>>
  228. $section,                 $files,    $bytes,     $pctfiles, $pctbytes
  229. .
  230.  
  231. $| = 1;
  232. $- = 0;
  233. $^ = top2;
  234. $~ = line2;
  235.  
  236. foreach $section ( sort bytecompare keys(groupfiles) ) {
  237.  
  238.    $files = $groupfiles{$section};
  239.    $bytes = $groupbytes{$section};
  240.    $pctbytes = sprintf("%8.2f", 100 * $groupbytes{$section} / $xferbytes);
  241.    $pctfiles = sprintf("%8.2f", 100 * $groupfiles{$section} / $xferfiles);
  242.    write;
  243.  
  244. }
  245.  
  246. if ( $xferfiles < 1 ) { $xferfiles = 1; }
  247. if ( $xferbytes < 1 ) { $xferbytes = 1; }
  248. }
  249.  
  250. if ($opt_d) {
  251. format top3 =
  252.  
  253. Total Transfer Amount By Domain
  254.  
  255.              Number Of    Number of     Average    Percent Of  Percent Of
  256. Domain Name  Files Sent   Bytes Sent   Xmit  Rate  Files Sent  Bytes Sent
  257. -----------  ----------  ------------  ----------  ----------  ----------
  258. .
  259.  
  260. format line3 =
  261. @<<<<<<<<<<  @>>>>>>>>>  @>>>>>>>>>>>  @>>>>>>>>>  @>>>>>>>    @>>>>>>>  
  262. $domain,     $files,     $bytes,       $avgrate,   $pctfiles,  $pctbytes
  263. .
  264.  
  265. $- = 0;
  266. $^ = top3;
  267. $~ = line3;
  268.  
  269. foreach $domain ( sort domnamcompare keys(domainfiles) ) {
  270.  
  271.    if ( $domainsecs{$domain} < 1 ) { $domainsecs{$domain} = 1; }
  272.  
  273.    $files = $domainfiles{$domain};
  274.    $bytes = $domainbytes{$domain};
  275.    $avgrate  = sprintf("%5.1f KB/s",
  276.                   $domainbytes{$domain}/$domainsecs{$domain}/1000);
  277.    $pctfiles = sprintf("%8.2f", 100 * $domainfiles{$domain} / $xferfiles);
  278.    $pctbytes = sprintf("%8.2f", 100 * $domainbytes{$domain} / $xferbytes);
  279.    write;
  280.  
  281. }
  282.  
  283. print "\n";
  284. print "These figures only reflect ANONYMOUS FTP transfers.  There are many\n";
  285. print "sites which mount the archives via NFS, and those transfers are not\n";
  286. print "logged and reported by this program.\n\n";
  287.  
  288. }
  289.  
  290. if ($opt_h) {
  291.  
  292. format top8 =
  293.  
  294. Hourly Transmission Statistics
  295.  
  296.                  Number Of    Number of    Average    Percent Of  Percent Of
  297.      Time        Files Sent  Bytes  Sent  Xmit  Rate  Files Sent  Bytes Sent
  298. ---------------  ----------  -----------  ----------  ----------  ----------
  299. .
  300.  
  301. format line8 =
  302. @<<<<<<<<<<<<<<  @>>>>>>>>>  @>>>>>>>>>>  @>>>>>>>>>  @>>>>>>>    @>>>>>>>  
  303. $time,           $nfiles,    $nbytes,     $avgrate,   $pctfiles,  $pctbytes
  304. .
  305.  
  306.  
  307. $| = 1;
  308. $- = 0;
  309. $^ = top8;
  310. $~ = line8;
  311.  
  312. foreach $time ( sort keys(xfertbytes) ) {
  313.  
  314.    $nfiles   = $xfertfiles{$time};
  315.    $nbytes   = $xfertbytes{$time};
  316.    $avgrate  = sprintf("%5.1f KB/s", $xfertbytes{$time}/$xfertsecs{$time}/1000);
  317.    $pctfiles = sprintf("%8.2f", 100*$xfertfiles{$time} / $xferfiles);
  318.    $pctbytes = sprintf("%8.2f", 100*$xfertbytes{$time} / $xferbytes);
  319.    write;
  320. }
  321. }
  322. exit(0);
  323.  
  324. sub datecompare {
  325.  
  326.    $date1  = substr($a, 11, 4) * 4800;
  327.    $date2  = substr($b, 11, 4) * 4800;
  328.    $date1 += index("JanFebMarAprMayJunJulAugSepOctNovDec",substr($a, 4, 3))*400;
  329.    $date2 += index("JanFebMarAprMayJunJulAugSepOctNovDec",substr($b, 4, 3))*400;
  330.    $date1 += substr($a, 8, 2);
  331.    $date2 += substr($b, 8, 2);
  332.    $date1 - $date2;
  333.  
  334. }
  335.  
  336. sub domnamcompare {
  337.  
  338.    $sdiff = length($a) - length($b);
  339.    ($sdiff < 0) ? -1 : ($sdiff > 0) ? 1 : ($a lt $b) ? -1 : ($a gt $b) ? 1 : 0;
  340.  
  341. }
  342.  
  343. sub bytecompare {
  344.  
  345.    $bdiff = $groupbytes{$b} - $groupbytes{$a};
  346.    ($bdiff < 0) ? -1 : ($bdiff > 0) ? 1 : ($a lt $b) ? -1 : ($a gt $b) ? 1 : 0;
  347.  
  348. }
  349.  
  350. sub faccompare {
  351.  
  352.    $fdiff = $fac{$b} - $fac{$a};
  353.    ($fdiff < 0) ? -1 : ($fdiff > 0) ? 1 : ($a lt $b) ? -1 : ($a gt $b) ? 1 : 0;
  354.  
  355. }
  356.  
  357. ----CUT HERE -----------------------------------------------------------------
  358. -- 
  359. - Dave Datta@cs.uwp.edu
  360.  
  361.     "Information wants to be free." - Elektric Music
  362.